/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FormProduto.java
 *
 * Created on 14/06/2012, 19:10:14
 */
package br.softmarket.visao;

import br.softmarket.modelo.Ncm;
import br.softmarket.modelo.Produto;
import br.softmarket.modelo.UnidadeMedida;
import br.softmarket.persistence.DbMan;
import java.awt.Dimension;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;


/**
 *
 * @author maraujo2
 */
public class FormProduto extends javax.swing.JFrame {

    private List<Produto> listaProdutos;
    
    private List<Ncm> listNcm;
    
    private DefaultTableModel model;
    
    private DefaultTableModel modelUM;
    /** Creates new form FormProduto */
    public FormProduto() {
        initComponents();
        this.setTitle("SoftMarket - Produto");
        this.setSize(new Dimension(800, 600));
        this.setLocationRelativeTo(this);
        
        listaProdutos = new ArrayList<Produto>();
        listNcm = new ArrayList<Ncm>();
        
        model = new DefaultTableModel();
        model.addColumn("Código");
        model.addColumn("Descrição");
        jtNcm.setModel(model);
        
        modelUM = new DefaultTableModel();
        modelUM.addColumn("Código");
        modelUM.addColumn("Descrição");
        jtTabelaUM.setModel(modelUM);
    }
     
    private void validarCodigo() {
        jFormattedTextField1.addKeyListener(new KeyAdapter() {

            @Override
            public void keyReleased(KeyEvent e) {
                jFormattedTextField1.setText(jFormattedTextField1.getText().replaceAll("[^0-9]", ""));
            }
        });
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jtpProduto = new javax.swing.JTabbedPane();
        jpProduto = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jtfCodigoBarrasProduto = new javax.swing.JTextField();
        jtfDescricaoProduto = new javax.swing.JTextField();
        jtfApresentacaoProduto = new javax.swing.JTextField();
        jtfTipoProduto = new javax.swing.JTextField();
        jtfFornecedorProduto = new javax.swing.JTextField();
        jtfUnidadeMedidaProduto = new javax.swing.JTextField();
        jtfPrecoFabricaProduto = new javax.swing.JTextField();
        jtfPrecoVendaProduto = new javax.swing.JTextField();
        jtfPromocaoProduto = new javax.swing.JTextField();
        jtfValorEstoqueProduto = new javax.swing.JTextField();
        jtfIcmsIssProduto = new javax.swing.JTextField();
        jtfNCMProduto = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jtfImagemProduto = new javax.swing.JTextField();
        jbNovo = new javax.swing.JButton();
        jbGravar = new javax.swing.JButton();
        jbExcluir = new javax.swing.JButton();
        jbEditar = new javax.swing.JButton();
        jFormattedTextField1 = new javax.swing.JFormattedTextField();
        jpUnidadeMedida = new javax.swing.JPanel();
        jpCodigoUM = new javax.swing.JPanel();
        jtfCodigoUM = new javax.swing.JTextField();
        jpDescricaoUM = new javax.swing.JPanel();
        jtfDescricaoUM = new javax.swing.JTextField();
        jbGravarUnidadeMedida = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtTabelaUM = new javax.swing.JTable();
        jpNCM = new javax.swing.JPanel();
        jpCodigoNCM = new javax.swing.JPanel();
        jtfCodigoNCM = new javax.swing.JTextField();
        jpDescricaoNCM = new javax.swing.JPanel();
        jtfDescricaoNCM = new javax.swing.JTextField();
        jbGravarNcm = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtNcm = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(800, 600));

        jLabel1.setText("Código");

        jLabel2.setText("Código de barras");

        jLabel3.setText("Descrição");

        jLabel4.setText("Apresentaçao");

        jLabel5.setText("Tipo Produto");

        jLabel6.setText("Fornecedor");

        jLabel7.setText("Unidade Medida");

        jLabel8.setText("Preço Fabrica");

        jLabel9.setText("Preço Venda");

        jLabel10.setText("Promoção");

        jLabel11.setText("Valor Total Estoque");

        jLabel12.setText("ICMS/ISS");

        jLabel13.setText("NCM");

        jLabel14.setText("Imagem");

        jbNovo.setText("Novo");
        jbNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbNovoActionPerformed(evt);
            }
        });

        jbGravar.setText("Gravar");
        jbGravar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbGravarActionPerformed(evt);
            }
        });

        jbExcluir.setText("Excluir");
        jbExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbExcluirActionPerformed(evt);
            }
        });

        jbEditar.setText("Editar");

        javax.swing.GroupLayout jpProdutoLayout = new javax.swing.GroupLayout(jpProduto);
        jpProduto.setLayout(jpProdutoLayout);
        jpProdutoLayout.setHorizontalGroup(
            jpProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpProdutoLayout.createSequentialGroup()
                .addGroup(jpProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpProdutoLayout.createSequentialGroup()
                        .addGroup(jpProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel3)
                            .addComponent(jLabel5)
                            .addComponent(jLabel7)
                            .addComponent(jLabel13)
                            .addGroup(jpProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel9)))
                        .addGap(18, 18, 18)
                        .addGroup(jpProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jtfDescricaoProduto, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE)
                            .addComponent(jtfTipoProduto)
                            .addComponent(jtfUnidadeMedidaProduto)
                            .addComponent(jtfPrecoVendaProduto)
                            .addComponent(jtfValorEstoqueProduto, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jtfNCMProduto, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jFormattedTextField1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 165, Short.MAX_VALUE)
                        .addGroup(jpProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jpProdutoLayout.createSequentialGroup()
                                .addComponent(jLabel14)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jtfImagemProduto, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpProdutoLayout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jtfApresentacaoProduto, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpProdutoLayout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jtfFornecedorProduto, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpProdutoLayout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jtfPrecoFabricaProduto, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpProdutoLayout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jtfPromocaoProduto, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpProdutoLayout.createSequentialGroup()
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jtfIcmsIssProduto, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpProdutoLayout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(37, 37, 37)
                                .addComponent(jtfCodigoBarrasProduto, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpProdutoLayout.createSequentialGroup()
                        .addGap(0, 347, Short.MAX_VALUE)
                        .addComponent(jbNovo)
                        .addGap(18, 18, 18)
                        .addComponent(jbGravar)
                        .addGap(18, 18, 18)
                        .addComponent(jbExcluir)
                        .addGap(18, 18, 18)
                        .addComponent(jbEditar)))
                .addContainerGap())
        );
        jpProdutoLayout.setVerticalGroup(
            jpProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpProdutoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jtfCodigoBarrasProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jFormattedTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfDescricaoProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jtfApresentacaoProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfTipoProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jtfFornecedorProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addGap(11, 11, 11)
                .addGroup(jpProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfUnidadeMedidaProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jtfPrecoFabricaProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfPrecoVendaProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(jtfPromocaoProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfValorEstoqueProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(jtfIcmsIssProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfNCMProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13)
                    .addComponent(jtfImagemProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14))
                .addGap(59, 59, 59)
                .addGroup(jpProdutoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbNovo)
                    .addComponent(jbGravar)
                    .addComponent(jbExcluir)
                    .addComponent(jbEditar))
                .addContainerGap(145, Short.MAX_VALUE))
        );

        jtpProduto.addTab("Produto", jpProduto);

        jpCodigoUM.setBorder(javax.swing.BorderFactory.createTitledBorder("Código"));

        javax.swing.GroupLayout jpCodigoUMLayout = new javax.swing.GroupLayout(jpCodigoUM);
        jpCodigoUM.setLayout(jpCodigoUMLayout);
        jpCodigoUMLayout.setHorizontalGroup(
            jpCodigoUMLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jtfCodigoUM, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
        );
        jpCodigoUMLayout.setVerticalGroup(
            jpCodigoUMLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpCodigoUMLayout.createSequentialGroup()
                .addComponent(jtfCodigoUM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jpDescricaoUM.setBorder(javax.swing.BorderFactory.createTitledBorder("Descrição"));

        javax.swing.GroupLayout jpDescricaoUMLayout = new javax.swing.GroupLayout(jpDescricaoUM);
        jpDescricaoUM.setLayout(jpDescricaoUMLayout);
        jpDescricaoUMLayout.setHorizontalGroup(
            jpDescricaoUMLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jtfDescricaoUM, javax.swing.GroupLayout.DEFAULT_SIZE, 645, Short.MAX_VALUE)
        );
        jpDescricaoUMLayout.setVerticalGroup(
            jpDescricaoUMLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpDescricaoUMLayout.createSequentialGroup()
                .addComponent(jtfDescricaoUM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jbGravarUnidadeMedida.setText("Gravar");
        jbGravarUnidadeMedida.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbGravarUnidadeMedidaActionPerformed(evt);
            }
        });

        jtTabelaUM.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Código", "Descrição"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane2.setViewportView(jtTabelaUM);

        javax.swing.GroupLayout jpUnidadeMedidaLayout = new javax.swing.GroupLayout(jpUnidadeMedida);
        jpUnidadeMedida.setLayout(jpUnidadeMedidaLayout);
        jpUnidadeMedidaLayout.setHorizontalGroup(
            jpUnidadeMedidaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpDescricaoUM, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jpUnidadeMedidaLayout.createSequentialGroup()
                .addComponent(jpCodigoUM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(475, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpUnidadeMedidaLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jbGravarUnidadeMedida)
                .addGap(69, 69, 69))
            .addGroup(jpUnidadeMedidaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2)
                .addContainerGap())
        );
        jpUnidadeMedidaLayout.setVerticalGroup(
            jpUnidadeMedidaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpUnidadeMedidaLayout.createSequentialGroup()
                .addComponent(jpCodigoUM, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpDescricaoUM, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 308, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbGravarUnidadeMedida)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jtpProduto.addTab("Unidade de Medida", jpUnidadeMedida);

        jpCodigoNCM.setBorder(javax.swing.BorderFactory.createTitledBorder("Código"));
        jpCodigoNCM.setPreferredSize(new java.awt.Dimension(182, 53));

        javax.swing.GroupLayout jpCodigoNCMLayout = new javax.swing.GroupLayout(jpCodigoNCM);
        jpCodigoNCM.setLayout(jpCodigoNCMLayout);
        jpCodigoNCMLayout.setHorizontalGroup(
            jpCodigoNCMLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jtfCodigoNCM, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
        );
        jpCodigoNCMLayout.setVerticalGroup(
            jpCodigoNCMLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpCodigoNCMLayout.createSequentialGroup()
                .addComponent(jtfCodigoNCM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jpDescricaoNCM.setBorder(javax.swing.BorderFactory.createTitledBorder("Descrição"));

        javax.swing.GroupLayout jpDescricaoNCMLayout = new javax.swing.GroupLayout(jpDescricaoNCM);
        jpDescricaoNCM.setLayout(jpDescricaoNCMLayout);
        jpDescricaoNCMLayout.setHorizontalGroup(
            jpDescricaoNCMLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jtfDescricaoNCM)
        );
        jpDescricaoNCMLayout.setVerticalGroup(
            jpDescricaoNCMLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpDescricaoNCMLayout.createSequentialGroup()
                .addComponent(jtfDescricaoNCM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jbGravarNcm.setText("Gravar");
        jbGravarNcm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbGravarNcmActionPerformed(evt);
            }
        });

        jtNcm.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Código", "Descrição"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jtNcm);

        javax.swing.GroupLayout jpNCMLayout = new javax.swing.GroupLayout(jpNCM);
        jpNCM.setLayout(jpNCMLayout);
        jpNCMLayout.setHorizontalGroup(
            jpNCMLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpNCMLayout.createSequentialGroup()
                .addComponent(jpCodigoNCM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addComponent(jpDescricaoNCM, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpNCMLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jbGravarNcm)
                .addGap(134, 134, 134))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 657, Short.MAX_VALUE)
        );
        jpNCMLayout.setVerticalGroup(
            jpNCMLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpNCMLayout.createSequentialGroup()
                .addComponent(jpCodigoNCM, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpDescricaoNCM, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 100, Short.MAX_VALUE)
                .addComponent(jbGravarNcm)
                .addContainerGap())
        );

        jtpProduto.addTab("NCM", jpNCM);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jtpProduto, javax.swing.GroupLayout.Alignment.TRAILING)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jtpProduto, javax.swing.GroupLayout.Alignment.TRAILING)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbExcluirActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jbExcluirActionPerformed

    private void jbNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbNovoActionPerformed
        limparCampos();
    }//GEN-LAST:event_jbNovoActionPerformed

    private void jbGravarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbGravarActionPerformed
        
    }//GEN-LAST:event_jbGravarActionPerformed

    private void jbGravarNcmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbGravarNcmActionPerformed
        Ncm ncm = new Ncm();
        ncm.setCodNcm(Integer.parseInt(jtfCodigoNCM.getText()));
        ncm.setDescricaoNcm(jtfDescricaoNCM.getText());
        
        Vector vetor = new Vector();
        vetor.add(ncm.getCodNcm());
        vetor.add(ncm.getDescricaoNcm());
        model.addRow(vetor);

        JOptionPane.showMessageDialog(null, "Ncm inserido.");
        limparCamposNcm();
        
    }//GEN-LAST:event_jbGravarNcmActionPerformed

    private void jbGravarUnidadeMedidaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbGravarUnidadeMedidaActionPerformed
        UnidadeMedida um = new UnidadeMedida();
        um.setCodUnidadeMedida(Integer.parseInt(jtfCodigoUM.getText()));
        um.setDescUnidadeMedida(jtfDescricaoUM.getText());
        
        Vector vetor = new Vector();
        vetor.add(um.getCodUnidadeMedida());
        vetor.add(um.getDescUnidadeMedida());
        modelUM.addRow(vetor);
        JOptionPane.showMessageDialog(null, "Unidade de medida inserida.");
        limparCamposUnidadeMedida();
        
    }//GEN-LAST:event_jbGravarUnidadeMedidaActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("com.sun.java.swing.plaf.windows.WindowsLookAndFeel".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FormProduto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FormProduto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FormProduto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FormProduto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new FormProduto().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFormattedTextField jFormattedTextField1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton jbEditar;
    private javax.swing.JButton jbExcluir;
    private javax.swing.JButton jbGravar;
    private javax.swing.JButton jbGravarNcm;
    private javax.swing.JButton jbGravarUnidadeMedida;
    private javax.swing.JButton jbNovo;
    private javax.swing.JPanel jpCodigoNCM;
    private javax.swing.JPanel jpCodigoUM;
    private javax.swing.JPanel jpDescricaoNCM;
    private javax.swing.JPanel jpDescricaoUM;
    private javax.swing.JPanel jpNCM;
    private javax.swing.JPanel jpProduto;
    private javax.swing.JPanel jpUnidadeMedida;
    private javax.swing.JTable jtNcm;
    private javax.swing.JTable jtTabelaUM;
    private javax.swing.JTextField jtfApresentacaoProduto;
    private javax.swing.JTextField jtfCodigoBarrasProduto;
    private javax.swing.JTextField jtfCodigoNCM;
    private javax.swing.JTextField jtfCodigoUM;
    private javax.swing.JTextField jtfDescricaoNCM;
    private javax.swing.JTextField jtfDescricaoProduto;
    private javax.swing.JTextField jtfDescricaoUM;
    private javax.swing.JTextField jtfFornecedorProduto;
    private javax.swing.JTextField jtfIcmsIssProduto;
    private javax.swing.JTextField jtfImagemProduto;
    private javax.swing.JTextField jtfNCMProduto;
    private javax.swing.JTextField jtfPrecoFabricaProduto;
    private javax.swing.JTextField jtfPrecoVendaProduto;
    private javax.swing.JTextField jtfPromocaoProduto;
    private javax.swing.JTextField jtfTipoProduto;
    private javax.swing.JTextField jtfUnidadeMedidaProduto;
    private javax.swing.JTextField jtfValorEstoqueProduto;
    private javax.swing.JTabbedPane jtpProduto;
    // End of variables declaration//GEN-END:variables
    
    public void limparCampos() {
        jtfApresentacaoProduto.setText("");
        jtfCodigoBarrasProduto.setText("");
        jtfDescricaoProduto.setText("");
        jtfFornecedorProduto.setText("");
        jtfIcmsIssProduto.setText("");
        jtfImagemProduto.setText("");
        jtfNCMProduto.setText("");
        jtfPrecoFabricaProduto.setText("");
        jtfPrecoVendaProduto.setText("");
        jtfPromocaoProduto.setText("");
        jtfTipoProduto.setText("");
        jtfUnidadeMedidaProduto.setText("");
        jtfValorEstoqueProduto.setText("");
    }
    
    public void limparCamposNcm(){
        jtfCodigoNCM.setText("");
        jtfDescricaoNCM.setText("");
    }
    
    public void limparCamposUnidadeMedida(){
        jtfCodigoUM.setText("");
        jtfDescricaoUM.setText("");
    }

}
